﻿<%@page contentType="text/html; charset=utf-8" language="java"%>
<%@page import="java.util.*"%>

<%@page import="com.easidea.tim.entity.purchase.PurchaseReturnItem"%>
<%@page import="com.easidea.tim.entity.purchase.PurchaseReturn"%>
<%@page import="com.easidea.tim.service.purchase.PurchaseReturnService"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="com.easidea.tim.service.purchase.PurchaseReturnItemService"%>
<%@page import="java.text.DecimalFormat"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<%
	String id = request.getParameter("id").toString();
	
	String meter = "";
	String productname = "";
	String productcolor = "";

	DecimalFormat df = new DecimalFormat("###.000");
	DecimalFormat dfone = new DecimalFormat("###.0");
	DecimalFormat dfno = new DecimalFormat("###");
	double moneyTotal = 0; 
	double meterTotal = 0;
	double piTotal=0;
	String meterArray [] = null;
	PurchaseReturnItemService purchaseReturnItemService = new PurchaseReturnItemService();
	PurchaseReturnService purchaseReturnService = new PurchaseReturnService();
	
	WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
	List purchaseReturnlist = ((PurchaseReturnService)wac.getBean("purchaseReturnService")).GetPurchaseReturnListByid(new Integer(id).longValue());
	PurchaseReturn purchaseReturn = (PurchaseReturn)purchaseReturnlist.get(0);
	//PurchaseReturn purchaseReturn = purchaseReturnService.get(id);
	//List itemList = purchaseReturnItemDao.getItemsByOrderId(new Integer(id).longValue());
	List itemList = ((PurchaseReturnItemService)wac.getBean("purchaseReturnItemService")).getItemsByOrderId(new Integer(id).longValue());


	String customer = purchaseReturn.getSupplyer().getName();
	String address = purchaseReturn.getSupplyer().getAddress();
	String phone = purchaseReturn.getSupplyer().getContactorMobile()+";" + purchaseReturn.getSupplyer().getBizTel1();
	String memo = purchaseReturn.getMemo();
	String code = purchaseReturn.getFlowNo();
	String date = "";
	String type="退";

	if(purchaseReturn.getStatus()>2){
		date=purchaseReturn.getModifyTime().toLocaleString();
	}
	
 %>
<head>
    <title>可视化设计套打</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
     <OBJECT ID="jatoolsPrinter" CLASSID="CLSID:B43D3361-D975-4BE2-87FE-057188254255"
 license="MWUwMDFlNTE1ZTAyNWE2YjEyNTI1YzVmNzk0YjBjNTg1ZDVmNWYxYTVmNTA0NjVmNWY1Yzc5NGExYjU4NWQ1NTVkMDI1YjU3NGM0MTU4NWM1ZDE5NDQ1MTU3" codebase="http://192.168.70.7/wz-web/print/jatoolsPrinter.cab#version=5,5,0,0"></OBJECT>
    
    <style>
	.title { 
	   font-family : Arial,Vernada,Tahoma, sans-serif;
	   font-size: 30px;
	   color : #00008B;
	   background-color : White; text-decoration:underline
	}
	.normal{
		font-family : Arial,Vernada, Tahoma, Helvetica, sans-serif;
		font-size: 14px;
		color: #444444;
		text-decoration: none;
		line-height: 180%;        
	}
	
	#page1 DIV {
		position:absolute;
	}
	
	.f1,.f2,.f3,.f4,.f5,.f6,.f7,.f8{top:80;left:2;}
	
	.customer{top:84;left:115}
	.address{top:84;left:345}
	.phone{top:84;left:605}
	.metertotal{top:352;left:570}
	.moneytotal{top:352;left:640}
	.pitotal{top:352;left:500}
	.memo{top:352;left:115}
	.code{top:53;left:585}
	.date{top:23;left:510}
	<%
		
		int top = 108;
		int col = 0;
		String colid="";
		for(int i=0;i<itemList.size();i++){
			col = col +1;
		
			top = 134 + (col-1)*27;
			PurchaseReturnItem orderItem = (PurchaseReturnItem)itemList.get(i);
			meter = orderItem.getMeterNum();
			piTotal = piTotal + orderItem.getPiNum();
			meterTotal = orderItem.getTotalMeter() + meterTotal;
			moneyTotal = (orderItem.getTotalMeter() * orderItem.getUnitPrice()) + moneyTotal;
			meterArray = meter.split(",");
			
			if(col==1){
				colid = "a";
			}else if(col == 2){
				colid = "b";
			}else if(col == 3){
				colid = "c";
			}else if(col == 4){
				colid = "d";
			}else if(col == 5){
				colid = "e";
			}else if(col == 6){
				colid = "f";
			}else if(col == 7){
				colid = "g";
			}else if(col == 8){
				colid = "h";
			}
	%>
		.my-<%=colid%>1{top:<%=top%>;left:75}
		.my-<%=colid%>2{top:<%=top%>;left:150}
		<%
			for(int j=0;j<meterArray.length;j++){
			if(j ==7||j==14||j==21||j==28||j==35||j==42||j==49||j==56){
				col = col + 1;
				top = 134 + 27*(col-1);
			}
			
			if(col==1){
				colid = "a";
			}else if(col == 2){
				colid = "b";
			}else if(col == 3){
				colid = "c";
			}else if(col == 4){
				colid = "d";
			}else if(col == 5){
				colid = "e";
			}else if(col == 6){
				colid = "f";
			}else if(col == 7){
				colid = "g";
			}else if(col == 8){
				colid = "h";
			}		
			

			
			if(j == 0){
			
		%>
		.my-<%=colid%>10{top:<%=top%>;left:480}	
		.my-<%=colid%>11{top:<%=top%>;left:520}	
		.my-<%=colid%>12{top:<%=top%>;left:560}	
		.my-<%=colid%>13{top:<%=top%>;left:650}	 
		<%
			}

			if(j < 7){
		%>
		.my-<%=colid%><%= j+3%>{top:<%=top%>;left:<%=150+((j+1)*42)%>}
		
		<%
			}
		%>
		<%
			if(j==7||j==14||j==21||j==28||j==35||j==42||j==49){
		 %>
		.my-<%=colid%>1{top:<%=top%>;left:<%=150+(1*42)%>}
		 <%
			 }
		  %>
		  <%
			if(j==8||j==15||j==22||j==29||j==36||j==43||j==50){
		 %>
		.my-<%=colid%>2{top:<%=top%>;left:<%=150+(2*42)%>}
		 <%
			 }
		  %>
		  <%
			if(j==9||j==16||j==23||j==30||j==37||j==44||j==51){
		 %>
			.my-<%=colid%>3{top:<%=top%>;left:<%=150+(3*42)%>}
		 <%
			 }
		  %>
		  <%
			if(j==10||j==17||j==24||j==31||j==38||j==45||j==52){
		 %>
		 .my-<%=colid%>4{top:<%=top%>;left:<%=150+(4*42)%>}
		 <%
			 }
		  %>
		  <%
			if(j==11||j==18||j==25||j==32||j==39||j==46||j==53){
		 %>
		.my-<%=colid%>5{top:<%=top%>;left:<%=150+(5*42)%>}
		 <%
			 }
		  %>
		  <%
			if(j==12||j==19||j==26||j==33||j==40||j==47||j==54){
		 %>
		.my-<%=colid%>6{top:<%=top%>;left:<%=150+(6*42)%>}
		 <%
			 }
		  %>
		  <%
			if(j==13||j==20||j==27||j==34||j==41||j==48||j==55){
		 %>
		.my-<%=colid%>7{top:<%=top%>;left:<%=150+(7*42)%>}
		 <%
			 }
		  %>

	<%
		}
		}
		
	%>
	</style>
			  <script language="JavaScript">
	function doPrint(isPreview)	{
	
	    myDoc = {
	        settings: {
	            pageWidth: 2100,
	            pageHeight: 1150,

	            orientation: 1},//打印纸张方向，纵向为1横向为2
			
	        documents: document,
	        marginIgnored:true,
	        //dragDesigner:true,
	        dragDesigner:{viewSource:false},
	        loadPrintSettings:true,
	        savePrintSettings:true, 
	        settingsID: 'purchaseP<%=id%>',
		    enableScreenOnlyClass:true,
	        copyrights:'杰创软件拥有版权   www.jatools.com'
	    };
	
	   if(isPreview){
				jatoolsPrinter.printPreview(myDoc); //预览
			}else{
				jatoolsPrinter.print(myDoc,true); // 打印弹出打印机的选择框  
			}
	}
	window.onload = function() { doPrint(true); } //直接打印预览			
	</script>
</head>
<body>&nbsp;&nbsp; &nbsp; 
<body >
<p class="title"><input type="button" value="打印预览" onClick="doPrint();"></p>

<div style='padding:0;background-color:#808080;width:215mm;height:120mm;overflow:auto;'>

	<div id="page1" style='padding-left:0px,padding-top:7px;width:210mm;height:112mm;position:relative'>
		<img class='screen-only' src="../image/madan2.jpg" style='position:absolute;width:100%;height:100%;'/>
		<div id='customer' draggable='true' class='customer my-customer' style='position:absolute;font-size: 13;' ><%=customer %></div>
		<div id='address' draggable='true' class='address my-address' style='position:absolute;font-size: 13;' ><%=address %></div>
		<div id='phone' draggable='true' class='phone my-phone' style='position:absolute;font-size: 13;' ><%=phone %></div>
		<div id='memo' draggable='true' class='memo my-memo' style='position:absolute;font-size: 13;' ><%=memo %></div>
		<div id='metertotal' draggable='true' class='metertotal my-metertotal' style='position:absolute;font-size: 14;font-family:Arial' ><%=dfone.format(meterTotal) %></div>
		<div id='moneyTotal' draggable='true' class='moneyTotal my-moneyTotal' style='position:absolute;font-size: 14;font-family:Arial' ><%=Double.parseDouble(df.format(moneyTotal)) %></div>
		<div id='pitotal' draggable='true' class='pitotal my-pitotal' style='position:absolute;font-size: 14;font-family:Arial' ><%="匹数:"+dfno.format(piTotal) %></div>
		<div id='code' draggable='true' class='code my-code' style='position:absolute;font-size:16;' ><%=type + code %></div>
		<div id='date' draggable='true' class='date my-date' style='position:absolute;font-size:16;' >出库日期：<%=date %></div>
		<%
		
		col = 0;
		colid="";
		for(int i=0;i<itemList.size();i++){
			col = col +1;
			PurchaseReturnItem orderItem = (PurchaseReturnItem)itemList.get(i);
			meter = orderItem.getMeterNum();
			productname = orderItem.getProductName();
			productcolor = orderItem.getProductColor();

			meterArray = meter.split(",");
			
			if(col==1){
				colid = "a";
			}else if(col == 2){
				colid = "b";
			}else if(col == 3){
				colid = "c";
			}else if(col == 4){
				colid = "d";
			}else if(col == 5){
				colid = "e";
			}else if(col == 6){
				colid = "f";
			}else if(col == 7){
				colid = "g";
			}else if(col == 8){
				colid = "h";
			}	
	%>
		<div id='<%= colid%>1' draggable='true' class='<%= colid%>1 my-<%= colid%>1' style='position:absolute;font-family:Arial;font-size: 14' ><%= productname%></div>
		<div id='<%= colid%>2' draggable='true' class='<%= colid%>2 my-<%= colid%>2' style='position:absolute;font-family:Arial;font-size: 14' ><%= productcolor%></div>

		<%
			for(int j=0;j<meterArray.length;j++){
			if(j ==7||j==14||j==21||j==28||j==35||j==42||j==49||j==56){
				col = col + 1;
			}

				if(col==1){
				colid = "a";
			}else if(col == 2){
				colid = "b";
			}else if(col == 3){
				colid = "c";
			}else if(col == 4){
				colid = "d";
			}else if(col == 5){
				colid = "e";
			}else if(col == 6){
				colid = "f";
			}else if(col == 7){
				colid = "g";
			}else if(col == 8){
				colid = "h";
			}
		if(j == 0){
			
		%>
        <div id='<%= colid%>10' draggable='true' class='<%= colid%>10 my-<%= colid%>10' style='position:absolute;font-family:Arial' ><%=orderItem.getUnitPrice()%></div>
		<div id='<%= colid%>11' draggable='true' class='<%= colid%>11 my-<%= colid%>11' style='position:absolute;font-family:Arial' ><%= dfno.format(orderItem.getPiNum())%></div>
		<div id='<%= colid%>12' draggable='true' class='<%= colid%>12 my-<%= colid%>12' style='position:absolute;font-family:Arial' ><%= dfone.format(orderItem.getTotalMeter())%></div>
		<div id='<%= colid%>13' draggable='true' class='<%= colid%>13 my-<%= colid%>13' style='position:absolute;font-family:Arial' ><%= Double.parseDouble(df.format(orderItem.getUnitPrice()*orderItem.getTotalMeter()))%></div>	
		<%
			}	
			if(j < 7){
		%>
		<div id='<%= colid%><%=j+3 %>' draggable='true' class='<%= colid%><%=j+3 %> my-<%= colid%><%=j+3 %>' style='position:absolute;font-family:Arial' ><%= Double.parseDouble(meterArray[j])%></div>
		<%
			}
		 %>
		<%
			if(j==7||j==14||j==21||j==28||j==35||j==42||j==49){
		 %>
		 <div id='<%= colid%>1' draggable='true' class='<%= colid%>1 my-<%= colid%>1' style='position:absolute;font-family:Arial' ><%=Double.parseDouble(meterArray[j])%></div>
		 <%
			 }
		  %>
		  <%
			if(j==8||j==15||j==22||j==29||j==36||j==43||j==50){
		 %>
		 <div id='<%= colid%>2' draggable='true' class='<%= colid%>2 my-<%= colid%>2' style='position:absolute;font-family:Arial' ><%=Double.parseDouble(meterArray[j])%></div>
		 <%
			 }
		  %>
		  <%
			if(j==9||j==16||j==23||j==30||j==37||j==44||j==51){
		 %>
		 <div id='<%= colid%>3' draggable='true' class='<%= colid%>3 my-<%= colid%>3' style='position:absolute;font-family:Arial' ><%=Double.parseDouble(meterArray[j])%></div>
		 <%
			 }
		  %>
		  <%
			if(j==10||j==17||j==24||j==31||j==38||j==45||j==52){
		 %>
		 <div id='<%= colid%>4' draggable='true' class='<%= colid%>4 my-<%= colid%>4' style='position:absolute;font-family:Arial' ><%=Double.parseDouble(meterArray[j])%></div>
		 <%
			 }
		  %>
		  <%
			if(j==11||j==18||j==25||j==32||j==39||j==46||j==53){
		 %>
		 <div id='<%= colid%>5' draggable='true' class='<%= colid%>5 my-<%= colid%>5' style='position:absolute;font-family:Arial' ><%=Double.parseDouble(meterArray[j])%></div>
		 <%
			 }
		  %>
		  <%
			if(j==12||j==19||j==26||j==33||j==40||j==47||j==54){
		 %>
		 <div id='<%= colid%>6' draggable='true' class='<%= colid%>6 my-<%= colid%>6' style='position:absolute;font-family:Arial' ><%=Double.parseDouble(meterArray[j])%></div>
		 <%
			 }
		  %>
		  <%
			if(j==13||j==20||j==27||j==34||j==41||j==48||j==55){
		 %>
		 <div id='<%= colid%>7' draggable='true' class='<%= colid%>7 my-<%= colid%>7' style='position:absolute;font-family:Arial' ><%=Double.parseDouble(meterArray[j])%></div>
		 <%
			 }
		  %>

	<%
		}
		}
		
	%>

	</div>
</div>

</body>
</html>
